package cn.kgc.online.common.handler;

import cn.kgc.online.common.constants.ResultCodeEnum;
import cn.kgc.online.common.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(KgcOnlineException.class)
    public R kgcOnlineRxecption(KgcOnlineException kgcOnlineException){
        log.error(kgcOnlineException.getMessage());
//        return R.setResult(ResultCodeEnum.KGC_DIY_EXCEPTION);
        return R.error().code(kgcOnlineException.getCode()).message(kgcOnlineException.getMessage());
    }


    @ResponseBody
    @ExceptionHandler(NullPointerException.class)
    public R nullPointerExecption(NullPointerException nullPointerException) {
        log.error(nullPointerException.getMessage());
        return R.setResult(ResultCodeEnum.NULL_POINTER_EXCEPTION);
    }


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R error(Exception e) {
        log.error(e.getMessage());
        return R.error();
    }




}
